package com.epower.web.action.epowerwordfrequency;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.epower.base.BaseAction;
import com.epower.bo.epower.commons.Result;
import com.epower.bo.epowerwordfrequency.EpowerWordFrequencyService;
import com.epower.dataobject.EpowerWordFrequencyDO;

@Scope("prototype")
@Component()
public class WordFrequencyAction extends BaseAction {

	/**
     * 
     */
	private static final long serialVersionUID = 1L;
	private String spelling;
	private EpowerWordFrequencyService epowerWordFrequencyBO;
	private Result result = Result.succResult();
	 /*** 查询对象 ***/
    private EpowerWordFrequencyDO query;
    
    /*** 对象集合 ***/
    private List<EpowerWordFrequencyDO> epowerWordFrequencyList;
    
	/***
     * 列表视图
     * 
     * @return
     * @throws Exception
     */
    public String listEpowerWordFrequency() throws Exception {
        // 初始化查询条件
        if (query == null) {
            query = new EpowerWordFrequencyDO();
            query.setStatus(1);
            //query.setCategoryid(1);
        }
        // 查询列表
        epowerWordFrequencyList = epowerWordFrequencyBO.getEpowerWordFrequencyListPageByOption(query);
        pages = this.getPagesList(query.getToPage(), query.getTotalPage());
        return SUCCESS;
    }
    
	public String queryEpowerWordBySpelling() throws Exception {
		// 初始化查询条件
		if (spelling == null) {
			return ERROR;
		}
		List<EpowerWordFrequencyDO> wordFrequencys = epowerWordFrequencyBO.queryEpowerWordFrequencyBySpelling(spelling);
		List<TmpWord> tmps = new ArrayList<TmpWord>();
		for (EpowerWordFrequencyDO tmp : wordFrequencys) {
			TmpWord tmpword = new TmpWord();
			tmpword.setId(tmp.getId());
			tmpword.setSpelling(tmp.getSpelling());
			tmps.add(tmpword);
		}
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("words", tmps);
		result.setResult(resultMap);
		return SUCCESS;
	}

	public String queryEpowerMainWordBySpelling() throws Exception {
		// 初始化查询条件
		if (spelling == null) {
			return ERROR;
		}
		List<EpowerWordFrequencyDO> wordFrequencys = epowerWordFrequencyBO.queryEpowerWordFrequencyBySpelling(spelling);
		List<TmpWord> tmps = new ArrayList<TmpWord>();
		for (EpowerWordFrequencyDO tmp : wordFrequencys) {
			TmpWord tmpword = new TmpWord();
			tmpword.setId(tmp.getId());
			tmpword.setSpelling(tmp.getSpelling());
			tmps.add(tmpword);
		}
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("words", tmps);
		result.setResult(resultMap);
		return SUCCESS;

	}

	public String getSpelling() {
		return spelling;
	}

	public void setSpelling(String spelling) {
		this.spelling = spelling;
	}

	public EpowerWordFrequencyService getEpowerWordFrequencyBO() {
		return epowerWordFrequencyBO;
	}

	public void setEpowerWordFrequencyBO(EpowerWordFrequencyService epowerWordFrequencyBO) {
		this.epowerWordFrequencyBO = epowerWordFrequencyBO;
	}

	public Result getResult() {
		return result;
	}

	public void setResult(Result result) {
		this.result = result;
	}
	
    public EpowerWordFrequencyDO getQuery() {
        return query;
    }
    
    public void setQuery(EpowerWordFrequencyDO query) {
        this.query = query;
    }
    
    public List<EpowerWordFrequencyDO> getEpowerWordFrequencyList() {
        return epowerWordFrequencyList;
    }
    
    public void setEpowerWordFrequencyList(List<EpowerWordFrequencyDO> epowerWordFrequencyList) {
        this.epowerWordFrequencyList = epowerWordFrequencyList;
    }

    public class TmpWord {

		private Integer id;
		private String spelling;

		public Integer getId() {
			return id;
		}

		public void setId(Integer id) {
			this.id = id;
		}

		public String getSpelling() {
			return spelling;
		}

		public void setSpelling(String spelling) {
			this.spelling = spelling;
		}

	}
}
